<?php

/*

	$param
		to 		: comma seperated emails
		cc		:
		bcc		:
		from	: 
		subject : subject part of email (text only!)
		message : message part of email (text or html)
		

*/

class spEmail
{
	private $param;

	public function __construct( $param=null )
	{
		$this->param = $param;
	}

	public function send( $bCreateHtmlBody=false )
	{
		// required
		$to 		= isset($this->param["to"])?$this->param["to"]:"";
		$subject 	= $this->param["subject"];
		$message 	= $this->param["message"];
		
		if ( $message instanceof spElement )
			$message = $message->getHtml();
			
		if ( $bCreateHtmlBody )
		{
			$message = "
				<html>
					<head>
						<title>Tumbling Team Fyn</title>
					</head>
					<body>
					".stripslashes($message)."
					</body>
				</html>
			";
		}			
		
		$header = "MIME-Version: 1.0\r\n";
		$header.= "Content-type: text/html; charset=utf-8\r\n";
		
		if ( $this->param["from"] )
			$header.= "From: ".$this->param["from"]."\r\n";
			
		if ( $this->param["bcc"] )
			$header.= "Bcc: ".$this->param["bcc"]."\r\n";
		
		return mail( $to, $subject, $message, $header );
	}
	
	// this requires that the pear package is installed.
	public function testpear()
	{
		$from = "<test@gmail.com>";
		$to = "<marino.peter@gmail.com>";
		$subject = "Hi!";
		$body = "Hi,\n\nHow are you?";

		$host = "ssl://smtp.gmail.com";
		$port = "465";
		$username = "<tumblingteamfyn@gmail.com>";
		$password = "somethingspecial";

		$headers = array(
			'From' => $from,
			'To' => $to,
			'Subject' => $subject
		);
		
		$smtp = Mail::factory(
			'smtp',
			array ('host' => $host,
				'port' => $port,
				'auth' => true,
				'username' => $username,
				'password' => $password));

		$mail = $smtp->send($to, $headers, $body);

		if (PEAR::isError($mail)) {
		  echo("<p>" . $mail->getMessage() . "</p>");
		 } else {
		  echo("<p>Message successfully sent!</p>");
		}
	}
}

?>